<template>
  <div class="app-container">
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="项目名称" prop="project_name">
        <el-input
          v-model="queryParams.project_name"
          placeholder="请输入项目名称"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="入库编号" prop="warehousing_id">
        <el-input
          v-model="queryParams.warehousing_id"
          placeholder="请输入入库编号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="入库状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="入库状态" clearable size="small">
          <el-option label="未入库" value="0" />
          <el-option label="全部入库" value="1" />
          <el-option label="部分入库" value="2" />
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="订单类型" prop="customer_order_type">-->
      <!--        <el-select v-model="queryParams.customer_order_type" placeholder="订单类型" clearable size="small">-->
      <!--          <el-option label="采购入库" value="采购入库" />-->
      <!--          <el-option label="退货入库" value="退货入库" />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-action="'warehousing@create'"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="入库编号">
              <span>{{ props.row.warehousing_id }}</span>
            </el-form-item>
            <el-form-item label="结算方">
              <span>{{ props.row.settlement }}</span>
            </el-form-item>
            <!--            <el-form-item label="订单组号">-->
            <!--              <span>{{ props.row.group_number }}</span>-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="关联订单号">-->
            <!--              <span>{{ props.row.relation_order }}</span>-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="后置作业单号">-->
            <!--              <span>{{ props.row.postposition_order }}</span>-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="参考单号1">-->
            <!--              <span>{{ props.row.odd_numbers_one }}</span>-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="参考单号2">-->
            <!--              <span>{{ props.row.odd_numbers_two }}</span>-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="参考单号3">-->
            <!--              <span>{{ props.row.odd_numbers_three }}</span>-->
            <!--            </el-form-item>-->
            <el-form-item label="录入方式">
              <span>{{ props.row.entry_method }}</span>
            </el-form-item>
            <el-form-item label="创建时间">
              <span>{{ props.row.created_at }}</span>
            </el-form-item>
            <el-form-item label="备注">
              <span>{{ props.row.remarks }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="project_name" label="项目/委托方" align="center" :show-overflow-tooltip="true">
        <template v-slot="scope">
          <span>{{ scope.row.project_name +'/'+ scope.row.project_name_two }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column prop="customer_order_type" label="订单类型" align="center" />-->
      <el-table-column prop="customer_business_number" label="客户业务单号" align="center" />
      <el-table-column prop="goods_number" label="商品总数量" align="center" />
      <el-table-column prop="actual_number" label="入库数量" align="center" />
      <el-table-column prop="status" label="入库状态" align="center">
        <template v-slot="scope">
          <span v-if="scope.row.status === '0'">未入库</span>
          <span v-else-if="scope.row.status === '1'">全部入库</span>
          <span v-else-if="scope.row.status === '2'">部分入库</span>
        </template>
      </el-table-column>
      <el-table-column prop="pub_name" label="发布人" align="center" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status !== '1'"
            v-action="'warehousingSon@index'"
            size="mini"
            type="success"
            @click="goods(scope.row)"
          >添加商品
          </el-button>
          <el-button
            v-if="scope.row.status === '1'"
            v-action="'warehousingSon@index'"
            size="mini"
            type="success"
            @click="goods(scope.row)"
          >详细
          </el-button>
          <el-button
            v-if="scope.row.status !== '1'"
            v-action="'warehousing@update'"
            size="mini"
            type="primary"
            @click="handleEdit(scope.row)"
          >修改
          </el-button>
          <el-button
            v-if="scope.row.status === '0'"
            v-action="'warehousing@delete'"
            size="mini"
            type="danger"
            @click="handleDel(scope.row)"
          >删除
          </el-button>

          <el-button
            v-action="'warehousingSon@print'"
            size="mini"
            type="warning"
            @click="prints(scope.row)"
          >打印
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getList" />
    <!-- 新增/修改 -->
    <AddEdit :open.sync="open" :title="title" :form="form" :select-data="selectData" @getList="getList" />
    <!-- 打印 -->
    <Print :open-one.sync="openOne" :warehousing_id="warehousing_id" />
  </div>
</template>
<script>
// eslint-disable-next-line no-unused-vars
import { warehousingList, warehousingDel, warehousingPrint } from '@/api/storehouse'
import AddEdit from './AddEdit'
import Print from './Print'
export default {
  name: 'Index',
  components: {
    AddEdit,
    Print
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      open: false,
      openOne: false,
      title: '',
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      form: {},
      selectData: [],
      // 查询参数
      queryParams: {
        page: 1,
        limit: 10,
        warehousing_id: undefined,
        status: undefined,
        customer_order_type: undefined
      },
      show: false,
      ids: [],
      warehousing_id: ''
    }
  },
  created() {
    const id = this.$route.query.id
    if (id) {
      this.queryParams.warehousing_id = id
    }
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      const that = this
      this.loading = true
      warehousingList(this.queryParams).then(response => {
        if (response.code === 10000) {
          that.list = response.data
          that.total = response.count
          that.loading = false
        }
      })
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.form = {}
      this.open = true
      this.title = '添加'
    },
    /** 编辑按钮操作 */
    handleEdit(row) {
      this.form = JSON.parse(JSON.stringify(row))
      this.open = true
      this.title = '编辑'
    },
    /** 删除按钮操作 */
    handleDel(row) {
      const that = this
      that.$confirm('是否删除该数据？？？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        that.loading = true
        warehousingDel({ id: row.id.toString() }).then(response => {
          that.loading = false
          if (response.code === 10000) {
            that.$message.success(response.message)
            that.getList()
          } else {
            that.$message.error(response.message)
          }
        })
      }).catch(() => {
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        page: 1,
        limit: 10,
        warehousing_id: undefined,
        status: undefined,
        customer_order_type: undefined
      }
      this.handleQuery()
    },
    /** 入库商品 */
    goods(row) {
      this.$router.push({
        path: '/warehousing/goods',
        query: { warehousing_id: row.warehousing_id, status: row.status }
      })
    },
    /** 打印 */
    prints(row) {
      this.openOne = true
      this.warehousing_id = row.warehousing_id
    }
  }
}
</script>

